/*
 *  Copyright [2012] Paulo de Tarso
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package revendedora.entidades;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import javax.persistence.*;

/**
 *
 * @author Tarso
 */
@Entity
@Table(name="TB_PRODUTOS",schema="REVENDAAVON")
public class Produto implements Serializable, Comparable<Produto> {

    @Id @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Column(name="ID")
    private Long id;
    
    @Column(name="CODIGO_LN", length=8, nullable=false)
    private Long codigoLn;
    
    @Column(name="DESCRICAO", length=300, nullable=false)
    private String descricao;
    
    @Column(name="VALOR", scale=2, precision=17, nullable=false)
    private BigDecimal valor;

    @OneToMany(cascade= CascadeType.MERGE, mappedBy="produto")
    private List<ItemCampanha> itensRelacionados;
    
    public Produto() {
        this(0l, null, null, null);
    }

    public Produto(Long id, Long codigoLn, String descricao, BigDecimal valor) {
        this.id = id;
        this.codigoLn = codigoLn;
        this.descricao = descricao;
        this.valor = valor;
    }

    @Override
    public int compareTo(Produto o) {
        return this.compareTo(o);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Produto other = (Produto) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        if (!Objects.equals(this.codigoLn, other.codigoLn)) {
            return false;
        }
        if (!Objects.equals(this.descricao, other.descricao)) {
            return false;
        }
        if (!Objects.equals(this.valor, other.valor)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 83 * hash + Objects.hashCode(this.id);
        hash = 83 * hash + Objects.hashCode(this.codigoLn);
        hash = 83 * hash + Objects.hashCode(this.descricao);
        hash = 83 * hash + Objects.hashCode(this.valor);
        return hash;
    }

    @Override
    public String toString() {
        return "Produtos{" + "id=" + id + ", codigoLn=" + codigoLn + ", descricao=" + descricao + ", valor=" + valor + '}';
    }

    public Long getCodigoLn() {
        return codigoLn;
    }

    public void setCodigoLn(Long codigoLn) {
        this.codigoLn = codigoLn;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public BigDecimal getValor() {
        return valor;
    }

    public void setValor(BigDecimal valor) {
        this.valor = valor;
    }
}
